<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="ConfigParser-objects.html" />
<link rel="prev" href="module-ConfigParser.html" />
<link rel="parent" href="module-ConfigParser.html" />
<link rel="next" href="ConfigParser-objects.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>9.2.1 RawConfigParser Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="9.2 configparser  "
  href="module-ConfigParser.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="9.2 configparser  "
  href="module-ConfigParser.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="9.2.2 configparser Objects"
  href="ConfigParser-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-ConfigParser.html">9.2 ConfigParser  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-ConfigParser.html">9.2 ConfigParser  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="ConfigParser-objects.html">9.2.2 ConfigParser Objects</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION0011210000000000000000"></a><a name="RawConfigParser-objects"></a>
<br>
9.2.1 RawConfigParser Objects 
</h2>

<p>
<tt class="class">RawConfigParser</tt> instances have the following methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2058' xml:id='l2h-2058' class="method">defaults</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a dictionary containing the instance-wide defaults.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2059' xml:id='l2h-2059' class="method">sections</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a list of the sections available; <code>DEFAULT</code> is not
included in the list.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2060' xml:id='l2h-2060' class="method">add_section</tt></b>(</nobr></td>
  <td><var>section</var>)</td></tr></table></dt>
<dd>
Add a section named <var>section</var> to the instance.  If a section by
the given name already exists, <tt class="exception">DuplicateSectionError</tt> is
raised.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2061' xml:id='l2h-2061' class="method">has_section</tt></b>(</nobr></td>
  <td><var>section</var>)</td></tr></table></dt>
<dd>
Indicates whether the named section is present in the
configuration. The <code>DEFAULT</code> section is not acknowledged.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2062' xml:id='l2h-2062' class="method">options</tt></b>(</nobr></td>
  <td><var>section</var>)</td></tr></table></dt>
<dd>
Returns a list of options available in the specified <var>section</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2063' xml:id='l2h-2063' class="method">has_option</tt></b>(</nobr></td>
  <td><var>section, option</var>)</td></tr></table></dt>
<dd>
If the given section exists, and contains the given option,
return <tt class="constant">True</tt>; otherwise return <tt class="constant">False</tt>.

<span class="versionnote">New in version 1.6.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2064' xml:id='l2h-2064' class="method">read</tt></b>(</nobr></td>
  <td><var>filenames</var>)</td></tr></table></dt>
<dd>
Attempt to read and parse a list of filenames, returning a list of filenames
which were successfully parsed.  If <var>filenames</var> is a string or
Unicode string, it is treated as a single filename.
If a file named in <var>filenames</var> cannot be opened, that file will be
ignored.  This is designed so that you can specify a list of potential
configuration file locations (for example, the current directory, the
user's home directory, and some system-wide directory), and all
existing configuration files in the list will be read.  If none of the
named files exist, the <tt class="class">ConfigParser</tt> instance will contain an
empty dataset.  An application which requires initial values to be
loaded from a file should load the required file or files using
<tt class="method">readfp()</tt> before calling <tt class="method">read()</tt> for any optional
files:

<p>
<div class="verbatim"><pre>
import ConfigParser, os

config = ConfigParser.ConfigParser()
config.readfp(open('defaults.cfg'))
config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
</pre></div>

<span class="versionnote">Changed in version 2.4:
Returns list of successfully parsed filenames.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2065' xml:id='l2h-2065' class="method">readfp</tt></b>(</nobr></td>
  <td><var>fp</var><big>[</big><var>, filename</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Read and parse configuration data from the file or file-like object in
<var>fp</var> (only the <tt class="method">readline()</tt> method is used).  If
<var>filename</var> is omitted and <var>fp</var> has a <tt class="member">name</tt> attribute,
that is used for <var>filename</var>; the default is "<tt class="samp">&lt;???&gt;</tt>".
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2066' xml:id='l2h-2066' class="method">get</tt></b>(</nobr></td>
  <td><var>section, option</var>)</td></tr></table></dt>
<dd>
Get an <var>option</var> value for the named <var>section</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2067' xml:id='l2h-2067' class="method">getint</tt></b>(</nobr></td>
  <td><var>section, option</var>)</td></tr></table></dt>
<dd>
A convenience method which coerces the <var>option</var> in the specified
<var>section</var> to an integer.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2068' xml:id='l2h-2068' class="method">getfloat</tt></b>(</nobr></td>
  <td><var>section, option</var>)</td></tr></table></dt>
<dd>
A convenience method which coerces the <var>option</var> in the specified
<var>section</var> to a floating point number.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2069' xml:id='l2h-2069' class="method">getboolean</tt></b>(</nobr></td>
  <td><var>section, option</var>)</td></tr></table></dt>
<dd>
A convenience method which coerces the <var>option</var> in the specified
<var>section</var> to a Boolean value.  Note that the accepted values
for the option are <code>"1"</code>, <code>"yes"</code>, <code>"true"</code>, and <code>"on"</code>,
which cause this method to return <code>True</code>, and <code>"0"</code>, <code>"no"</code>,
<code>"false"</code>, and <code>"off"</code>, which cause it to return <code>False</code>.  These
string values are checked in a case-insensitive manner.  Any other value will
cause it to raise <tt class="exception">ValueError</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2070' xml:id='l2h-2070' class="method">items</tt></b>(</nobr></td>
  <td><var>section</var>)</td></tr></table></dt>
<dd>
Return a list of <code>(<var>name</var>, <var>value</var>)</code> pairs for each
option in the given <var>section</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2071' xml:id='l2h-2071' class="method">set</tt></b>(</nobr></td>
  <td><var>section, option, value</var>)</td></tr></table></dt>
<dd>
If the given section exists, set the given option to the specified
value; otherwise raise <tt class="exception">NoSectionError</tt>.  While it is
possible to use <tt class="class">RawConfigParser</tt> (or <tt class="class">ConfigParser</tt> with
<var>raw</var> parameters set to true) for <em>internal</em> storage of
non-string values, full functionality (including interpolation and
output to files) can only be achieved using string values.

<span class="versionnote">New in version 1.6.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2072' xml:id='l2h-2072' class="method">write</tt></b>(</nobr></td>
  <td><var>fileobject</var>)</td></tr></table></dt>
<dd>
Write a representation of the configuration to the specified file
object.  This representation can be parsed by a future <tt class="method">read()</tt>
call.

<span class="versionnote">New in version 1.6.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2073' xml:id='l2h-2073' class="method">remove_option</tt></b>(</nobr></td>
  <td><var>section, option</var>)</td></tr></table></dt>
<dd>
Remove the specified <var>option</var> from the specified <var>section</var>.
If the section does not exist, raise <tt class="exception">NoSectionError</tt>. 
If the option existed to be removed, return <tt class="constant">True</tt>;
otherwise return <tt class="constant">False</tt>.

<span class="versionnote">New in version 1.6.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2074' xml:id='l2h-2074' class="method">remove_section</tt></b>(</nobr></td>
  <td><var>section</var>)</td></tr></table></dt>
<dd>
Remove the specified <var>section</var> from the configuration.
If the section in fact existed, return <code>True</code>.
Otherwise return <code>False</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2075' xml:id='l2h-2075' class="method">optionxform</tt></b>(</nobr></td>
  <td><var>option</var>)</td></tr></table></dt>
<dd>
Transforms the option name <var>option</var> as found in an input file or
as passed in by  client code to the form that should be used in the
internal structures.  The default implementation returns a lower-case
version of <var>option</var>; subclasses may override this or client code
can set an attribute of this name on instances to affect this
behavior.  Setting this to <tt class="function">str()</tt>, for example, would make
option names case sensitive.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="9.2 configparser  "
  href="module-ConfigParser.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="9.2 configparser  "
  href="module-ConfigParser.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="9.2.2 configparser Objects"
  href="ConfigParser-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-ConfigParser.html">9.2 ConfigParser  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-ConfigParser.html">9.2 ConfigParser  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="ConfigParser-objects.html">9.2.2 ConfigParser Objects</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
